#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>


struct Number {
	long long value;
	int count3;
	int count2;
	Number() {
		value = 0;
		count3 = 0;
		count2 = 0;
	}
	Number(long long v) {
		value = v;
		count3 = 0;
		count2 = 0;

		long long tmp = v;
		while(tmp % 3 == 0) {
			count3++;
			tmp /= 3;
		}
		while (tmp % 2 == 0) {
			count2++;
			tmp /= 2;
		}
	}
} numbers[60];


bool MyCompare(const Number& n1, const Number& n2) {
	if (n1.count2 != n2.count2) {
		return n1.count2 < n2.count2;
	}

	return n1.count3 > n2.count3;

}

/**
 * 时间复杂度：O(nlogn)
 * 空间复杂度：O(1)
 * 
 * 乘法和除法
 * @return 
 */
int main() {
	
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		long long v;
		scanf("%lld", &v);
		numbers[i] = Number(v);
	}

	std::sort(numbers, numbers + n, MyCompare);

	for (int i = 0; i < n; i++) {
		printf("%lld ", numbers[i].value);
	}

	return 0;
}